package leetcode_1100;


/**
 *@author 周杨 
 *ConvertToBaseNeg2_1017_ 将一个数化成-1进制的字符串 
 *describe:很巧妙 用栈的思想 使数值接近0 
 *2019年5月18日 下午12:25
 */
public class ConvertToBaseNeg2_1017_ {
	public static void main(String[] args) {
		ConvertToBaseNeg2_1017_ test = new ConvertToBaseNeg2_1017_();
		System.out.println(test.baseNeg2(7));
	}
	
	public String baseNeg2(int N) {
		if(N == 0) return "0";
		StringBuilder sb = new StringBuilder();
		int tmp = 0;
		while(N != 0) {
			tmp = Math.abs(N%-2);
			sb.insert(0,tmp);
			N = (N-tmp)/-2;
		}
        return sb.toString();
    }
}
